import com.adobe.cairngorm.control.CairngormEventDispatcher;

import mx.events.CloseEvent;
import mx.events.ValidationResultEvent;
import mx.managers.PopUpManager;

import net.optix.ip.events.AddInventorEvent;
import net.optix.ip.model.ModelLocator;
import net.optix.ip.vo.InventorVO;
            
[Bindable]
public var model:ModelLocator	=	ModelLocator.getInstance(); 
  			
[Bindable]
private var messageP:String	=	
  		'Welcome to IP Manager.\n\n'+
  		'You are registered to access the IP Manager site for '+model.client.business+' .\n\n'+
  		'This email address is your userid.  Login here using your email address as the password.';
  			public function init():void
  			{
  				model.bSubmit	=	true;
  				model.result	=	"";
  				model.close		=	"no";
  			}
  			
            private function titleWindow_close(evt:CloseEvent):void { 
                model.result	=	"";
                PopUpManager.removePopUp(this); 
            }
            
            public function addInventor():void
            {	
            	var result:Boolean	=	true;

				var resultValidate:ValidationResultEvent;
				
				resultFirstName.text	=	"";
				resultLastName.text		=	"";
				resultEmail.text		=	"";
				
				model.result			=	"";
				
				resultValidate	=	stringValidator.validate(firstName.text);
            	if(resultValidate.type == ValidationResultEvent.INVALID)
            	{
            		result	=	false;
            		resultFirstName.text	=	
            			resultValidate.message;
            	}
            	
            	resultValidate	=	stringValidator.validate(lastName.text);
            	if(resultValidate.type == ValidationResultEvent.INVALID)
            	{
            		result	=	false;
            		resultLastName.text	=	
            			resultValidate.message;
            	}
            	
            	resultValidate	=	emailValidator.validate(email.text);
            	if(resultValidate.type == ValidationResultEvent.INVALID)
            	{
            		result	=	false;
            		resultEmail.text	=	
            			resultValidate.message;
            	}
            	
            	model.bSubmit	=	false;
            	model.result	=	"";
            	
            	
            	
            	if(result == true)
            	{
            		var vo:InventorVO = new InventorVO();
            		vo.clientID		=	model.client.clientID;
            		vo.firstName	=	firstName.text;
            		vo.lastName		=	lastName.text;
            		vo.email		=	email.text;
					vo.message		=	message.text;
            		var event:AddInventorEvent	=	new AddInventorEvent(vo);
            		CairngormEventDispatcher.getInstance().dispatchEvent( event );
            	}
            	else
            	{
            		model.bSubmit	=	true;
            	}
            }
            
            public function clear():void
            {
            	
            }